/**
 * Created with IntelliJ IDEA.
 * Description: leetcode.简单题.多数元素
 */

class Solution {
    public int majorityElement(int[] nums) {
        int max = 0;
        int count = 1;
        for(int i = 1; i < nums.length; i++) {
            if(nums[i] == nums[max]){
                count++;
            }else{
                count--;
            }
            if(count == 0){
                max = i + 1;
            }
        }
        return nums[max];
    }
}

public class Test {

}
